﻿package com.wandian.view.components.ui
{
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZButtonFour;
	import com.wandian.util.CLZSlideTwo;
	import com.wandian.util.CLZTabBar;

	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class SetPanel extends Object
	{
		private var _mcPanel:Sprite;
		private var _tabBar:CLZTabBar;
		private var _contentMc:Sprite;

		public function SetPanel(_setPanel:Sprite)
		{
			this._mcPanel=_setPanel;
			AddBtn.initBtn(this._mcPanel, CLZNoticeName.HIDE_SET_PANEL, AddBtn.CLOSE_TWO, "", 4, 5);
			this._contentMc=new Sprite();
			this._mcPanel.addChild(this._contentMc);
			var tabs:Array=[[this._mcPanel["sound_btn"], GameData.tip["SOUND_NAME"]]];
			this._tabBar=new CLZTabBar(tabs);
			var count:int=0;
			while (count < tabs.length)
			{

				tabs[count][0].addEventListener(Event.CHANGE, this.changeTabBarHandler);
				count=count + 1;
			}
			this._tabBar.setClickIndex(this._mcPanel["sound_btn"]);
			return;
		}

		private function changeTabBarHandler(event:Event):void
		{
			GameData.removeNumChildre(this._contentMc);
			switch (event.target.name)
			{
				case "sound_btn":
				{
					this.setSound(GameData.getSprite("SoundContent"));
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		}

		private function setSound(soundContent:Sprite):void
		{
			var isBan:Boolean;
			var _slide:CLZSlideTwo;
			var onSoundHandler:Function;
			var changeSlideHandler:Function;
			var mcSound:*=soundContent;
			onSoundHandler=function(event:MouseEvent=null):void
			{
				if (event == null)
				{
					if (SoundManage.volume == 0)
					{
						isBan=true;
						CLZButtonFour.initBtn(mcSound["sound_btn"], false);
					}
					else
					{
						CLZButtonFour.initBtn(mcSound["sound_btn"], true);
					}
				}
				else if (SoundManage.volume == 0)
				{
					CLZButtonFour.initBtn(mcSound["sound_btn"], true);
					SoundManage.volume=_slide.cureValue / 100;
				}
				else
				{
					isBan=true;
					CLZButtonFour.initBtn(mcSound["sound_btn"], false);
					SoundManage.volume=0;
				}
				return;
			};
			changeSlideHandler=function(event:Event):void
			{
				if (SoundManage.volume == 0)
				{
					onSoundHandler(null);
				}
				else
				{
					if (SoundManage.volume > 0)
					{
					}
					if (isBan)
					{
						onSoundHandler(null);
						isBan=false;
					}
				}
				SoundManage.volume=_slide._value / 100;
				trace(_slide._value);
				return;
			};
			isBan;
			this._contentMc.addChild(mcSound);
			mcSound.x=20.55;
			mcSound.y=79.5;
			if (SoundManage.volume == 0)
			{
				isBan;
				CLZButtonFour.setButton(mcSound["sound_btn"], "", false);
			}
			else
			{
				CLZButtonFour.setButton(mcSound["sound_btn"], "", true);
			}
			mcSound["sound_btn"].addEventListener(MouseEvent.CLICK, onSoundHandler);
			CLZButton.setButton(mcSound["slide_mc"]["sub_btn"]);
			CLZButton.setButton(mcSound["slide_mc"]["add_btn"]);
			CLZButton.setButton(mcSound["slide_mc"]["btn"]);
			_slide=new CLZSlideTwo(mcSound["slide_mc"]["btn"], mcSound["slide_mc"]["bg"], mcSound["slide_mc"]["sub_btn"], mcSound["slide_mc"]["add_btn"]);
			_slide.width=mcSound["slide_mc"]["bg"].width - mcSound["slide_mc"]["btn"].width;
			_slide.addEventListener(Event.CHANGE, changeSlideHandler);
			_slide.setMinMax(0, 100, SoundManage.volume * 100);
			return;
		}

	}
}
